using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering.Universal;

public class DynamicLightCullingController:MonoBehaviour {

	Light2D[] lights;

	void Start() {
		lights=GetComponentsInChildren<Light2D>();
	}



	private void FixedUpdate() {
		Vector2 cameraPosition = CameraController.instance.transform.position;

		Vector2 size = Vector2.up*CameraController.instance.camera.orthographicSize;
		size.x=size.y*CameraController.instance.camera.aspect;
		size+=Vector2.one*lights[0].pointLightOuterRadius;
		Vector2 distance = (Vector2)transform.position-cameraPosition;
		bool inCamera = Mathf.Abs(distance.x)<size.x&&Mathf.Abs(distance.y)<size.y;
		foreach(var i in lights) i.gameObject.SetActive(inCamera);

	}
}
